package com.hotel.ordersystem.controller;

import com.hotel.customersystem.pojo.CustomerUser;
import com.hotel.customersystem.service.CustomerUserService;
import com.hotel.ordersystem.pojo.CommentReplyMongoDB;
import com.hotel.ordersystem.service.CommentReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/commentReply")
public class CommentReplyController {

    @Autowired
    private CommentReplyService commentReplyService;

    @Autowired
    private CustomerUserService customerUserService;

    /**
     * 添加用户回复(回复楼主)
     * @param map1
     * @return
     */
    @PostMapping("/saveCommentReply")
    public String saveCommentReply(@RequestBody Map<String,CommentReplyMongoDB> map1){
        CommentReplyMongoDB commentEplyMongoDB = map1.get("commentEplyMongoDB");
        System.out.println(commentEplyMongoDB);
        CustomerUser customerUser = customerUserService.getById(commentEplyMongoDB.getUser2());
        String id = UUID.randomUUID().toString();
        commentEplyMongoDB.setCommentReplyId(id);
        commentEplyMongoDB.setUser2UserName(customerUser.getUserNickName());
        commentEplyMongoDB.setUser2Photo(customerUser.getStandby02());
        commentEplyMongoDB.setCommentTime(String.valueOf(LocalDateTime.now()));
        String result = commentReplyService.saveCommentReply(commentEplyMongoDB);
        commentReplyService.saveRabbitCommentReply(commentEplyMongoDB.getUser1(),commentEplyMongoDB.getUser2(),commentEplyMongoDB.getCommentText());
        return result;
    }

    /**
     * 查询回复楼主的评论
     */
    @GetMapping("/getCommentReplyBig/{commentId}")
    public List<CommentReplyMongoDB> getCommentReplyBig(@PathVariable("commentId") String commentId){
        return commentReplyService.getCommentReplyBig(commentId);
    }

    @GetMapping("/saveRabbitCommentReply/{user1Id}/{user2Id}/{text}")
    public void saveRabbitCommentReply(@PathVariable("user1Id") String user1Id ,
                                       @PathVariable("user2Id") String user2Id ,
                                       @PathVariable("text") String text){
        commentReplyService.saveRabbitCommentReply(user1Id,user2Id,text);
    }

    @GetMapping("/updateRabbitCommentReply")
    public void updateRabbitCommentReply(){
        commentReplyService.setCommentReplyInformation();
    }

}
